<template>
  <div id="index" ref="appRef">
    <div class="bg">
      <!--进入时加载框-->
      <dv-loading v-if="loading">Loading...</dv-loading>
      <div v-else class="host-body">

        <!--第一行数据布局（数据平台）-->
        <div class="d-flex jc-center">
          <dv-decoration-10 class="dv-dec-10"/>
          <div class="d-flex jc-center">
            <dv-decoration-8 class="dv-dec-8" :color="decorationColor"/>
            <div class="title">
              <span class="title-text">数据平台</span>
              <dv-decoration-6
                  class="dv-dec-6"
                  :reverse="true"
                  :color="['#50e3c2', '#67a1e5']"
              />
            </div>
            <dv-decoration-8
                class="dv-dec-8"
                :reverse="true"
                :color="decorationColor"
            />
          </div>
          <dv-decoration-10 class="dv-dec-10-s"/>
        </div>

        <!-- 第二行(垫江人才网) 时间 -->
        <div class="d-flex jc-between px-2">
          <div class="d-flex aside-width">
            <div class="react-left ml-4 react-l-s">
              <span class="react-left"></span>
              <!--              <span class="text">数据分析1</span>-->
            </div>
            <div class="react-left ml-3">
              <!--              <span class="text">数据分析2</span>-->
            </div>
          </div>
          <div class="d-flex aside-width">
            <div class="react-right bg-color-blue mr-3">
              <span class="text fw-b">新愚公人才网</span>
            </div>
            <div class="react-right mr-4 react-l-s">
              <span class="react-after"></span>
              <span class="text"
              >{{ dateYear }} {{ dateWeek }} {{ dateDay }}</span
              >
            </div>
          </div>
        </div>

        <div class="body-box">
          <!-- 第三行数据 -->
          <div class="content-box">
            <!--各种数量显示组件-->
            <div class="center">
              <dv-border-box-13 style="height: 580px">
                <div class="up">
                  <div class="bg-color-black item" v-for="item in titleItem" :key="item.title">
                    <p class="ml-3 colorWhite fs-xxxl item-p">{{ item.title }}</p>
                    <div>
                      <dv-digital-flop class="dv-dig-flop ml-1 mt-5 pl-3" :config="item.number"/>
                    </div>
                  </div>
                </div>
              </dv-border-box-13>
            </div>

            <div>
              <!--地图组件-->
              <dv-border-box-12 style="height: 580px; width: 580px;">
                <centerLeft2/>
              </dv-border-box-12>
            </div>

            <div>
              <!--饼状图-->
              <dv-border-box-8 style="height: 580px; width: 1000px;">
                <centerLeft1/>
              </dv-border-box-8>
            </div>
            <div>
            </div>
          </div>

          <!-- 第四行数据 -->
          <div>

            <!--最新人才滚动-->
            <div style="float: right;">
              <dv-border-box-13 style="height: 350px; width: 500px;">
                <centerRight1/>
              </dv-border-box-13>
            </div>

            <!--每日访问量 柱状图-->
            <div style="float: right;">
              <dv-border-box-12 style="height: 350px; width: 890px;">
                <bottomRight/>
              </dv-border-box-12>
            </div>

            <!--岗位滚动-->
            <div>
              <dv-border-box-12 style="height: 350px; width: 500px;">
                <centerRight3/>
              </dv-border-box-12>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import {formatTime} from '../utils/index.js'
import drawMixin from "../utils/drawMixin"
import centerLeft1 from './centerLeft1'
import centerLeft2 from './centerLeft2'
import centerRight1 from './centerRight1'
import centerRight2 from './centerRight2'
import centerRight3 from './centerRight3'
import bottomRight from './bottomRight'

export default {
  mixins: [drawMixin],
  data() {
    return {
      cdata1: null,
      titleItem: [],
      timing: null,
      loading: true,
      dateDay: null,
      dateYear: null,
      dateWeek: null,
      weekday: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
      decorationColor: ['#568aea', '#000000']
    }
  },
  components: {
    centerLeft1,
    centerLeft2,
    centerRight1,
    centerRight2,
    bottomRight,
    centerRight3
  },
  mounted() {
    this.timeFn()
    this.cancelLoading()
    this.getCurrentYearDataTotal()

  },
  beforeDestroy() {
    clearInterval(this.timing)
  },
  methods: {
    timeFn() {
      this.timing = setInterval(() => {
        this.dateDay = formatTime(new Date(), 'HH: mm: ss')
        this.dateYear = formatTime(new Date(), 'yyyy-MM-dd')
        this.dateWeek = this.weekday[new Date().getDay()]
      }, 1000)
    },
    cancelLoading() {
      setTimeout(() => {
        this.loading = false
      }, 500)
    },

    //获取当前年份相关数据
    getCurrentYearDataTotal() {
      axios.post('api/data/dataTotal').then(res => {
        if (res.data.code == 200) {
          const cdata1 = {
            title: '本年简历数量',
            number: {
              number: [res.data.data.resumeTotal],
              toFixed: 0,
              textAlign: 'left',
              content: '{nt}个',
              style: {
                fontSize: 30,
                fill: '#ffaa00'
              }
            }
          }
          this.titleItem.push(cdata1)

          const cdata2 = {
            title: '本年岗位数量',
            number: {
              number: [res.data.data.postTotal],
              toFixed: 0,
              textAlign: 'left',
              content: '{nt}个',
              style: {
                fontSize: 30,
                fill: '#ffaa00'
              }
            }
          }
          this.titleItem.push(cdata2)

          const cdata3 = {
            title: '本年企业数量',
            number: {
              number: [res.data.data.enterpriseTotal],
              toFixed: 0,
              textAlign: 'left',
              content: '{nt}个',
              style: {
                fontSize: 30,
                fill: '#ffaa00'
              }
            }
          }
          this.titleItem.push(cdata3)

          const cdata4 = {
            title: '本年用户数量',
            number: {
              number: [res.data.data.userTatal],
              toFixed: 0,
              textAlign: 'left',
              content: '{nt}个',
              style: {
                fontSize: 30,
                fill: '#ffaa00'
              }
            }
          }
          this.titleItem.push(cdata4)

        }
      }).catch(err => {
        console.log(err);
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../assets/scss/index.scss';

.center {
  display: flex;
  flex-direction: column;

  .up {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    padding: 10px;

    .item {
      border-radius: 6px;
      padding-top: 10px;
      margin-top: 20px;
      width: 100%;
      // width: 300px;
      // height: 100px;
      height: 120px;

      .dv-dig-flop {
        // width: 150px;
        width: 270px;
        height: 30px;
      }
    }
  }

  .item-p {
    height: 40px;
    line-height: 40px;
    font-size: 18px;
  }

  .down {
    padding: 10px;
    padding-bottom: 0;
    width: 100%;
    display: flex;
    // height: 255px;
    height: 345px;
    justify-content: space-between;

    .bg-color-black {
      border-radius: 5px;
    }

    .ranking {
      padding-top: 10px;
      width: 100%;

      .dv-scr-rank-board {
        padding: 10px;
        height: 250px;
      }
    }

    .percent {
      width: 100%;
      display: flex;
      flex-wrap: wrap;

      .item {
        width: 50%;
        // width: 100%;
        // height: 200px;
        height: 300px;
        padding-top: 10px;

        span {
          display: inline-block;
          text-align: center;
          vertical-align: middle;
          width: 100%;
          height: 30px;
          line-height: 30px;
          // font-size: 14px;
          // display: flex;
          // justify-content: center;
        }
      }
    }
  }
}
</style>
